package yxy.game.pm2.command.conquest;

import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.ConquestMessage;
import yxy.game.pm2.module.conquest.ConquestModule;

/** 征战 通关奖励领取进度 */
@MessageType(proto = Command.ConquestBonusReceiveProgress, classtype = ConquestMessage.ConquestBonusReceiveProgressRequest.class)
public class CMD_ConquestBonusReceiveProgress extends Command<ConquestMessage.ConquestBonusReceiveProgressRequest> {

	@Override
	public void execute(MessageSource messageSource, ConquestMessage.ConquestBonusReceiveProgressRequest request) {
		String playerCode = messageSource.getTag();

		ConquestMessage.ConquestBonusReceiveProgressResponse.Builder response = ConquestMessage.ConquestBonusReceiveProgressResponse.newBuilder();

		ConquestModule conquestModule = ConquestModule.get(playerCode);
		for (Integer levelRewardId : conquestModule.getLevelReward()) {
			response.addIds(levelRewardId);
		}

		send(messageSource, response, Result.Success);
	}

	private void send(MessageSource messageSource, ConquestMessage.ConquestBonusReceiveProgressResponse.Builder response, Result result) {
		response.setResult(result.packResult());
		MessageEmitterHandler.getInstance().send(messageSource, response.build());
	}
}